using System.Collections;
using System.Collections.Generic;
using BCW;
using UnityEngine;

public class PanelEndGameReward : MonoBehaviour
{
	[SerializeField]
	private UILabel title1;

	[SerializeField]
	private UILabel title2;

	[SerializeField]
	private UIGrid grid;

	[SerializeField]
	private GameObject lineAwardExample;

	[SerializeField]
	private UIScrollBar scrollBar;

	[SerializeField]
	private UIScrollView scrollView;

	[SerializeField]
	private GameObject noVipBG;

	[SerializeField]
	private GameObject vipBG;

	[SerializeField]
	private GameObject activeFrame;

	[SerializeField]
	private GameObject buttonBuyVip;

	[SerializeField]
	private GameObject labelBuyVip;

	public GameObject NoVipBG
	{
		get
		{
			return noVipBG;
		}
	}

	public GameObject VipBG
	{
		get
		{
			return vipBG;
		}
	}

	public GameObject ActiveFrame
	{
		get
		{
			return activeFrame;
		}
	}

	public GameObject ButtonBuyVip
	{
		get
		{
			return buttonBuyVip;
		}
	}

	public GameObject LabelBuyVip
	{
		get
		{
			return labelBuyVip;
		}
	}

	public void SetTitle(string title)
	{
		title1.text = title;
		title2.text = title;
	}

	public void ShowRewards(List<SessionReputationReward> rewards)
	{
		StartCoroutine(ShowRewardsCoroutine(rewards));
	}

	private IEnumerator ShowRewardsCoroutine(List<SessionReputationReward> rewards)
	{
		scrollBar.gameObject.SetActive(rewards.Count > 5);
		Dictionary<string, PanelEndGameRewardLine> tmpDictionary = new Dictionary<string, PanelEndGameRewardLine>();
		foreach (SessionReputationReward tmpReward in rewards)
		{
			PanelEndGameRewardLine tmpLineRewardScript2 = new PanelEndGameRewardLine();
			string rewardId = ((!string.IsNullOrEmpty(tmpReward.rewardID)) ? tmpReward.rewardID : tmpReward.type.ToString());
			if (!tmpDictionary.ContainsKey(rewardId))
			{
				GameObject tmpLineReward = Object.Instantiate(lineAwardExample);
				tmpLineReward.transform.SetParent(grid.transform);
				tmpLineReward.transform.localScale = Vector3.one;
				tmpLineRewardScript2 = tmpLineReward.GetComponent<PanelEndGameRewardLine>();
				tmpDictionary.Add(rewardId, tmpLineRewardScript2);
				tmpLineReward.SetActive(true);
			}
			else
			{
				tmpLineRewardScript2 = tmpDictionary[rewardId];
			}
			SetTexture(tmpLineRewardScript2, tmpReward);
			tmpLineRewardScript2.texture.mainTexture = ReputationProductReward.GetTexture(tmpReward);
			tmpLineRewardScript2.Count += tmpReward.rewardCount;
			tmpLineRewardScript2.title.text = ReputationProductReward.GetName(tmpReward);
		}
		grid.repositionNow = true;
		yield return null;
		scrollView.ResetPosition();
	}

	private void SetTexture(PanelEndGameRewardLine rewardScript, SessionReputationReward reward)
	{
		rewardScript.texture = rewardScript.texture.ReplaceForCurrentPlatform();
		switch (reward.type)
		{
		case SessionReputationRewardType.Cash:
			rewardScript.texture.LoadTextureAndAlphaMask("NGUI_Textures/", "cash");
			return;
		case SessionReputationRewardType.Gold:
			rewardScript.texture.LoadTextureAndAlphaMask("NGUI_Textures/", "gold");
			return;
		case SessionReputationRewardType.Star:
			rewardScript.texture.LoadTextureAndAlphaMask("NGUI_Textures/", "Icon_Star");
			return;
		}
		Product product = MarketController.Instance.GetProduct(reward.rewardID);
		if (product is ProductVehicleSkin)
		{
			rewardScript.texture.LoadTextureAndAlphaMask("AtlasShopGuns/", "ASG_" + (product as ProductVehicleSkin).skinTextureName);
		}
		else if (product is ProductVehicleUpgrade || product is ProductFreeUpgrade)
		{
			rewardScript.texture.LoadTextureAndAlphaMask("AtlasShopGuns/Upgrades/", MarketController.Instance.GetProduct(reward.rewardID).texture.Replace("Upgrades/", string.Empty));
		}
		else
		{
			rewardScript.texture.LoadTextureAndAlphaMask("AtlasShopGuns/", MarketController.Instance.GetProduct(reward.rewardID).texture);
		}
	}
}
